#pragma once
#include <map>
#include <algorithm>
#include <memory>
#include <functional>

namespace umtl
{
	//////////////////////////////////////////////////////////////////////////
	//

	template< typename key_t, typename value_t >
	class map_tree : public std::map< key_t, map_tree< key_t, value_t > >
	{
	public:
		typedef key_t key_t;
		typedef value_t value_t;
		typedef std::map< key_t, map_tree< key_t, value_t > > map_type;
		typedef map_tree< key_t, value_t > type;
		typedef type tree_type;
		typedef std::tr1::function< void(value_t&val) > function;

		map_tree() {}
		map_tree( map_tree const & other )
			: map_type( other )
			, value_(other.value_)
		{}

		value_t & value() { return value_; }
		value_t const & value() const { return value_; }
		
		map_tree & operator=( value_t const & val ) {
			value_ = val;
			return *this;
		}

		void for_each( function func )
		{
			std::for_each( begin(), end(), 
				[&func]( map_type::value_type & child )
				{
					func( child.second.value_ );
					child.second.for_each( func );
				}
			);
		}

	private:
		value_t value_;

		void operator=( map_tree const & other );
	};

	//////////////////////////////////////////////////////////////////////////
}